<template>
	<view class="lc-numberBox">
		<view class="lc-minus" @click.stop="minus">-</view>
		<view class="lc-number"><input type="number" :disabled="isDisabled" v-model="inputValue" /></view>
		<view class="lc-add" @click.stop="add">+</view>
	</view>
</template>

<script>
export default {
	name: 'lc-number-box',
	props: {
		value: {
			type: [Number, String],
			default: 1
		},
		prdi: {
			type: Number,
			default: 0
		},
		min: {
			type: Number,
			default: 0
		},
		max: {
			type: Number,
			default: 99999
		},
		step: {
			type: Number,
			default: 1
		},
		disabled: {
			type: Boolean,
			default: false
		},
		color: {
			type: [Number, String],
			default: '#EF1C1C'
		},
		fillet: {
			type: Boolean,
			default: true
		}
	},
	data() {
		return {
			inputValue: 0,
			isDisabled: false,
			inputStep: 1
		}
	},
	created() {
		this.inputValue = +this.value
		this.isDisabled = this.disabled
		this.inputStep = parseFloat(this.step)
	},
	methods: {
		minus() {
			if (parseInt(this.inputValue) - parseInt(this.inputStep) < this.min) {
				return
			}
			this.inputValue = parseInt(this.inputValue) - parseInt(this.inputStep)
		},
		add() {
			if (parseInt(this.inputValue) + parseInt(this.inputStep) > this.max) {
				return
			}
			this.inputValue = parseInt(this.inputValue) + parseInt(this.inputStep)
		}
	},
	watch: {
		value(val) {
			if (val >= this.max) {
				this.inputValue = this.max
				return
			}
			this.inputValue = +val
		},
		inputValue(newVal, oldVal) {
			if (+newVal !== +oldVal) {
				this.$emit('change', newVal, this.prdi)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
$themeColor: rgb(87, 208, 127);
.lc-numberBox {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	.lc-minus,
	.lc-add {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 40rpx;
		height: 40rpx;
		border-radius: 50rpx;
		font-size: 40rpx;
		color: $themeColor;
		border: 1px solid $themeColor;
		color: #ef1c1c;
		border-color: #ef1c1c;
		border-radius: 99px;
	}
	.lc-number {
		padding: 0 20rpx;
		input {
			width: 100rpx;
			text-align: center;
		}
	}
}
</style>
